﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AFCEPF.BankApplication.BLL;
using NUnit.Framework;


namespace AFCEPF.BankApplication.Tests
{
    [TestFixture]
    class Test_AccountFactory
    {
        Customer _c;

        [SetUp]
        public void SetUp()
        {
            _c = new Customer("toto");
        }

        [Test]
        public void Test_Method_Create_ForSimple()
        {
            AccountBase result;            
            
            result = Bank.Instance.Accounts.Create(_c, AccountFactory.MIN_DEPOSIT_FOR_SIMPLE + 1);

            //Assert.IsTrue(result.GetType() == typeof(SimpleAccount));
            //Assert.IsTrue(result is SimpleAccount);

            Assert.IsInstanceOf<SimpleAccount>(result);
        }


        [Test]
        public void Test_Method_Create_ForSilver()
        {
            AccountBase result;            

            result = Bank.Instance.Accounts.Create(_c, AccountFactory.MIN_DEPOSIT_FOR_SILVER + 1);
            
            Assert.IsInstanceOf<SilverAccount>(result);
        }


        [Test]
        public void Test_Method_Create_ForGold()
        {
            AccountBase result;
            
            result = Bank.Instance.Accounts.Create(_c, AccountFactory.MIN_DEPOSIT_FOR_GOLD + 1);

            Assert.IsInstanceOf<GoldAccount>(result);
        }

        
        [Test]
        public void Test_Method_Create_ForException()
        {
            // Méthode avec une instance de delegate 
            // pointant vers une methode "standard"...

            //TestDelegate del = new TestDelegate(x);
            //Assert.Throws<InvalidDepositException>(del);

            // Méthode avec une instance de delegate 
            // anonyme..
            Assert.Throws<InvalidDepositException>(delegate()
            {
                Bank.Instance.Accounts.Create(_c, 0);
            });

        }


        [Test]
        public void Test_Method_Create_ForException2()
        {
            Exception ex = null;

            try
            {
                // Cet appel génère une InvalidDepositException.
                Bank.Instance.Accounts.Create(_c, 0);
            }
            catch (Exception caughtException)
            {
                ex = caughtException;
            }

            Assert.IsInstanceOf<InvalidDepositException>(ex);

        }



 
    }

}
